home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / delicious_bookmarks-2.0.64-fx.xpi / chrome / deliciousBookmarks.jar / content / ybSidebarOverlay.js < prev    next >
Encoding:
JavaScript  |  2008-06-19  |  5.2 KB  |  162 lines

  1. var ybsidebar = {
  2.   
  3.   lastSidebarSearchValue : "", //the last search term used on the sidebar / not overlay popup.
  4.   //_pinned : true, //this is being used from other files.  
  5.   
  6.   _showingPopup : false,   
  7.   _setFlagTimer : 0,
  8.  
  9.   _prefService : null, 
  10.   _originalTooltipPrefVal : true,  
  11.   _tooltipPrefName : "browser.chrome.toolbar_tips",
  12.   
  13.    onLoad: function() {
  14.       yDebug.print("Loading sidebar");
  15.       
  16.       ybsidebar._prefService = Components.classes["@mozilla.org/preferences-service;1"]
  17.                                  .getService(Components.interfaces.nsIPrefBranch);
  18.       var hideFFBMMenu = false;
  19.       try {
  20.         hideFFBMMenu = ybsidebar._prefService.getBoolPref("extensions.ybookmarks@yahoo.original.ui.hide");
  21.       } catch ( e ) {}
  22.       
  23.       /*if (hideFFBMMenu) {
  24.           var viewBookmarksSidebarKey =
  25.              document.getElementById( "viewBookmarksSidebarKb" );
  26.           viewBookmarksSidebarKey.setAttribute("command",
  27.                                                "viewYBookmarksSidebar");
  28.  
  29.           // This element is defined only on windows firefox. Check the existance of the element before
  30.           // using the element.
  31.           var viewBookmarksSidebarWinKey =
  32.              document.getElementById( "viewBookmarksSidebarWinKb" );
  33.           if ( viewBookmarksSidebarWinKey ) {
  34.             viewBookmarksSidebarWinKey.setAttribute("command",
  35.                                                   "viewYBookmarksSidebar");
  36.           }
  37.  
  38.           var viewBookmarksSidebar =
  39.              document.getElementById( "viewBookmarksSidebar" );
  40.           viewBookmarksSidebar.setAttribute("hidden", "true");
  41.  
  42.           // remove bookmarks button from the toolbar
  43.           var palette = document.getElementById( "navigator-toolbox" ).palette.firstChild;
  44.           while ( palette ) {
  45.             if ( palette.id == "bookmarks-button" ) {
  46.               palette.parentNode.removeChild ( palette );
  47.             }
  48.  
  49.             palette = palette.nextSibling;
  50.           } 
  51.        }*/
  52.       yDebug.print("Sidebar loaded", YB_LOG_MESSAGE);
  53.    },
  54.    
  55.    onUnload : function() {
  56.    
  57.    },
  58.    
  59.    togglePopup : function(event) {
  60.         
  61.      var popup = document.getElementById("ybsidebar-popup");
  62.      if ( this.isPopupHidden() )
  63.        this.showPopup(event);
  64.      else 
  65.        this.hidePopup();
  66.    },
  67.       
  68.    showPopup: function(event) {
  69.       /*    
  70.       var button = document.getElementById("del-button-delicious");
  71.       if (!button || !window.toolbar.visible)
  72.         return;
  73.      
  74.       var popup = document.getElementById("ybsidebar-popup");
  75.       popup.firstChild.setPopupSize();
  76.       popup.showPopup(button, -1, -1, "popup", "bottomleft", "topleft");
  77.       popup.firstChild.search(this.lastSidebarSearchValue);
  78.       popup.firstChild.setSearchBoxSelect();
  79.       popup.firstChild.setPopupShowing(true);
  80.       */ 
  81.    },
  82.  
  83.    hidePopup : function() {
  84.         /*
  85.      var popup = document.getElementById("ybsidebar-popup");
  86.      popup.firstChild.setPopupShowing(false);
  87.      popup.hidePopup();
  88.      */ 
  89.    },
  90.  
  91.    isPopupHidden : function() {
  92.  
  93.      if (this._showingPopup) {
  94.        return false;
  95.      }  
  96.      else {
  97.        return true;
  98.      }         
  99.    },
  100.  
  101.    setPopupShowedState : function() {
  102.  
  103.      this._showingPopup = true;
  104.      
  105.      //hack to fix the tooltip problem
  106.      this.storeOriginalTooltipPref();
  107.      this.setTooltipPref(false);
  108.    },  
  109.  
  110.    setPopupHiddenState : function() {
  111.           
  112.      //XXX: When the popup is opened, clicking the button would re-open the popup again
  113.      //In order to stop the popup opening again, a timeout is used to so that showingPopup = true
  114.      //for the next 500 ms.  When user releases the mouse button and within the 500ms, the popup would
  115.      //not be opened.
  116.      this._setFlagTimer = window.setTimeout(function(){ 
  117.                   ybsidebar._showingPopup = false; }, 500);
  118.      var popup = document.getElementById("ybsidebar-popup");
  119.      popup.firstChild.setPopupShowing(false);
  120.      
  121.      this.restoreOriginalTooltipPref();
  122.    },
  123.  
  124.    closeSidebar : function() {
  125.  
  126.      var sidebarBox = document.getElementById("sidebar-box");
  127.      var sidebarTitle = document.getElementById("sidebar-title");
  128.      var sidebarSplitter = document.getElementById("sidebar-splitter");
  129.      var elt = document.getElementById("viewYBookmarksSidebar");
  130.      if (elt.getAttribute("checked") == "true") {
  131.        elt.removeAttribute("checked");
  132.        sidebarBox.setAttribute("sidebarcommand", "");
  133.        sidebarTitle.setAttribute("value", "");
  134.        sidebarBox.hidden = true;
  135.        sidebarSplitter.hidden = true;
  136.        content.focus();
  137.        return;
  138.      }
  139.    },
  140.    
  141.    setTooltipPref : function(bool) {
  142.  
  143.      this._prefService.setBoolPref(this._tooltipPrefName, bool);
  144.    },
  145.    
  146.    storeOriginalTooltipPref : function() {
  147.  
  148.      try {
  149.  
  150.        this._originalTooltipPrefVal = this._prefService.getBoolPref(this._tooltipPrefName);
  151.      }
  152.      catch (e) { this._originalTooltipPrefVal = true; }
  153.    },
  154.    
  155.    restoreOriginalTooltipPref : function() {   
  156.      this.setTooltipPref(this._originalTooltipPrefVal);
  157.    }
  158. };
  159.  
  160. window.addEventListener("load", ybsidebar.onLoad, false);
  161. window.addEventListener("unload", ybsidebar.onUnload, false);
  162.